package
{
	import flash.display.MovieClip;
	import systems.events.BulletEvent;
	import systems.Weapon;
	import systems.States;
	import systems.EventChannel;
	
	/**
	 * @author Humberto Anjos
	 */
	public class Ship extends MovieClip
	{
		public static const LEFT = "left"
		public static const RIGHT = "right"
		public static const UP = "up"
		public static const DOWN = "down"
		
		private var _offset:int = 5
		private var _state:String
		private var _weapon:Weapon
		private var _world:GameWorld
		
		public function Ship(world:GameWorld, state:String, x:int, y:int)
		{
			this.x = x
			this.y = y
			
			_world = world
			_state = state
			
			_weapon = new Weapon()
			
			gotoAndStop(_state)
		}
		
		public function update()
		{
			_weapon.update()
		}
		
		public function move(direction:String)
		{
			switch(direction) {
				case LEFT:
					x -= _offset
					break
				case RIGHT:
					x += _offset
					break
				case UP:
					y -= _offset
					break
				case DOWN:
					y += _offset
					break
			}
		}
		
		public function shoot()
		{
			if(_weapon.tryToShoot())
				_world.newBullet(state, x, y - height / 2 - 1)
		}
		
		public function changeStateTo(event:String):void
		{
			if (_state == States.PURPLE) {
				_state = States.RED
			} else {
				_state = States.PURPLE
			}
			
			gotoAndStop(_state)
		}
		
		public function get state():String { return _state }
	}
}